<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal">
                    <input type="hidden" readonly id="productMember" name="productMember" class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">姓名:</label>
                        <div class="col-sm-2">
                            <input type="text" id="userName" name="userName"   class="form-control">
                        </div>
                        <label class="control-label col-sm-1">时间:</label>
                        <div class="col-sm-2">
                            <input type="text" id="performanceDate" name="performanceDate"   class="form-control">
                        </div>
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select id="performanceStatus" name="performanceStatus"  class="form-control">
                                <option value="">请选择</option>
                                <option value="99">待归档</option>
                                <option value="0">待审批</option>
                                <option value="1">审批中</option>
                                <option value="11">退回</option>
                                <option value="2">审批通过</option>
                                <option value="3">评分审批中</option>
                                <option value="31">重新审批中</option>
                                <option value="6">已结束</option>
                                <option value="7">已归档</option>
                            </select>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-1">部门:</label>
                        <div class="col-sm-2">
                            <select  id="groupName" name="groupName" xm-select="supplierId" xm-select-radio xm-select-search>
                                <%for(var dict in powerGroup){%>
                                <option value="${dict.groupName}">${dict.groupName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">评级:</label>
                        <div class="col-sm-2">
                            <select id="performanceLevel" name="performanceLevel"  class="form-control">
                                <option value="">请选择</option>
                                <option value="A">A</option>
                                <option value="B">B</option>
                                <option value="C">C</option>
                                <option value="D">D</option>
                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/human/performanceGrade/findByGrade.do"
                   class="table table-striped ta+ble-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="performanceId" name="performanceId">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">退回原因</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <textarea id="performanceRemark" name="performanceRemark" class="form-control" rows="3"></textarea>

                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload,chosen,chosen-demo'}){}%>
<script>
    var $relatedTable = $('#relatedTable'),selections=[];
    laydate.render({
        elem: '#performanceDate',
        type: 'month'
        ,trigger: 'click'
    });
    $(function(){
        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '部门',
                    field: 'groupName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '姓名',
                    field: 'userName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '时间',
                    field: 'performanceDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评分/总评分',
                    field: '',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r){
                        if(null == r.performanceScore){
                            return r.performanceSelfScore+"/"+ 0;
                        }else {
                            return r.performanceSelfScore + "/" + r.performanceScore;
                        }
                    }
                },
                {
                    title: '评级',
                    field: 'performanceLevel',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '状态',
                    field: 'performanceStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        switch (v) {
                            case 0:
                                return '<span class="badge badge-primary">待审批</span>';
                            case 1:
                                return '<span class="badge badge-warning-light">审批中</span>';
                            case 11:
                                return '<span class="badge badge-danger">退回</span>';
                            case 2:
                                return '<span class="badge badge-primary">待自评</span>';
                            case 3:
                                return '<span class="badge badge-warning-light">评分审批中</span>';
                            case 6:
                                return '<span class="badge badge-success">已结束</span>';
                            case 7:
                                return '<span class="badge badge-success">已归档</span>';
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/human/performanceRecord/main.do?performanceId='+id, 'yes']
                    });
                });
                $('.edit-btn').on('click',function(){//新增
                    var id=$(this).attr("data-val");
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/human/performance/addPage.do?id='+id, 'yes']
                    });
                });

                $('.check-return-btn').on('click',function(){//新增
                    var id=$(this).attr("data-val");
                    $("#performanceId").val(id);
                    layer.open({
                        type:1,
                        title:'退回',
                        area:['600px','300px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });

                //提交表单
                $('.check-pass-btn').on('click',function(){
                    var id=$(this).attr("data-val");
                    layer.confirm('确定要通过该绩效,一但提交无法修改？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        var index=layer.load();

                        $.post('/sea/human/performance/check.do',{id:id,performanceStatus:2},function(data){
                            if( data.ok ){
                                $relatedTable.bootstrapTable('refresh');
                                layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                                layer.close(index);
                            }else{
                                layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                                layer.close(index);
                            }
                        });
                    });
                });

                $('.grade-btn').on('click',function(){//新增
                    var id=$(this).attr("data-val");
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/human/performanceGrade/grade.do?id='+id, 'yes']
                    });
                });

            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });
    });
    //操作菜单
    function optFormatter(value,row){
        var content ='';
        if(row.performanceStatus==1 ) {
            //提交绩效
            content += '<button class="grade-btn btn btn-xs btn-success" data-val="' + row.id + '" title="修改"><i class="fa fa-thumbs-o-up"></i> 查看绩效</button>';
            content += '&nbsp;<button class="check-pass-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-thumbs-o-up"></i> 审核通过</button>';
            content += '&nbsp;<button class="check-return-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="修改"><i class="fa fa-times"></i> 退回</button>';
        }
        if(row.performanceStatus==3 || row.performanceStatus==31){
            content += '<button class="grade-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-thumbs-o-up"></i> 评分</button>';
        }
        content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.id+'" title="查看记录"> 查看记录</button>';
        return content;
    }
    $('.add-btn').on('click',function(){//新增
        layer.open({
            type: 2,
            area: ['800px','400px'],
            skin: 'layer-ext-espresso',
            content: ['/sea/human/performanceCheck/addPage.do', 'yes']
        });
    });



    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要退回当前绩效？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){

            layer.closeAll();
            var index=layer.load();
            $.post('/sea/human/performance/check.do',{id:$("#performanceId").val(),performanceStatus:11,performanceRemark:$("#performanceRemark").val()},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });




    $('.search-btn').on('click',function(){
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/human/performanceGrade/findByGrade.do?'+$('#search-form').serialize() });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/operate/related/export.do?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
